﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using System.Security.Principal;

namespace PC.AzureMultiApp.WebRoleMultiApp.Helpers
{
    [AttributeUsage(AttributeTargets.Method | AttributeTargets.Class, Inherited = true, AllowMultiple = true)]
    public class ValidaAdminRoleAttribute : AuthorizeAttribute
    {
        public override void OnAuthorization(AuthorizationContext filterContext)
        {
            var claimsppal = (Microsoft.IdentityModel.Claims.IClaimsPrincipal)HttpContext.Current.User;

            if (claimsppal != null && !claimsppal.IsInRole("Admins"))
            {
                HandleUnauthorizedRequest(filterContext);
                return;
            }
        }
    }
}

